package com.ecarx.library_base.base_widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ecarx.library_base.R;

public class ConfirmDialog extends Dialog implements View.OnClickListener {
    private static final String TAG = "ConfirmDialog";
    private ClickFinish clickFinish;
    private TextView text_name;

    private TextView text_message;
    private String messageContent;

    private TextView cancel_button;

    private TextView confirm_button;

    private String messageTitle;

    private Context mContext;

    public ConfirmDialog(@NonNull Context context, String messageTitle, String messageContent, ClickFinish clickFinish) {
        super(context, R.style.dialog_pwd);
        this.messageTitle = messageTitle;
        this.messageContent = messageContent;
        this.clickFinish = clickFinish;
        mContext = context;
    }

    public ConfirmDialog(@NonNull Context context, String messageContent, ClickFinish clickFinish) {
        super(context, R.style.dialog_pwd);
        mContext = context;
        this.messageTitle = mContext.getString(R.string.notice);
        this.messageContent = messageContent;
        this.clickFinish = clickFinish;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = LayoutInflater.from(mContext).inflate(R.layout.confirm_dialog, null);
        setContentView(view);
        initView(view);
        text_name.setText(messageTitle);
        text_message.setText(messageContent);
        initListener();
    }


    private void initListener() {
        cancel_button.setOnClickListener(this);
        confirm_button.setOnClickListener(this);
    }

    private void initView(View view) {
        text_name = (TextView) view.findViewById(R.id.message_title);
        text_message = (TextView) view.findViewById(R.id.message_content);
        cancel_button = (TextView) view.findViewById(R.id.cancel_button);
        confirm_button = (TextView) view.findViewById(R.id.confirm_button);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        dismiss();
        if (id == R.id.confirm_button) {
            clickFinish.onClickFinish();
        }
    }

    public interface ClickFinish {
        void onClickFinish();
    }
}
